package com.yequan.thread.singleton.serializable;

import java.io.ObjectStreamException;
import java.io.Serializable;

public class MyObject implements Serializable {

    private MyObject() {
    }

    private static class MyObjectFactory {
        private static MyObject myObject = new MyObject();
    }

    public static MyObject getInstance() {
        return MyObjectFactory.myObject;
    }

    protected Object readResolve() throws ObjectStreamException {
        System.out.println("调用了readResolve方法");
        return MyObjectFactory.myObject;
    }

}
